﻿using System.Collections.Generic;
using Api_Backstage.Code;
using Microsoft.AspNetCore.Mvc;

// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace Api.Controllers
{
    [Route("api/[controller]")]
    public class FriendsController : Controller
    {
        /// <summary>
        /// 添加好友
        /// </summary>
        [HttpPost("add")]
        [AuthAttribute]
        public ActionResult<Model.Result<string>> AddToFriends(string toMemberId, string message)
        {
            return Json(Utils.SecurityCall.SafeCall(() =>
            {
                return new BLL.Manage.FriendsManage().AddFriends(toMemberId, message);
            }));
        }

        /// <summary>
        /// 关于社交方面消息处理
        /// </summary>
        /// <param name="messageId">消息ID</param>
        /// <param name="messageHandleResult">处理方式  0为失败处理 1位成功处理</param>
        /// <param name="message">处理消息</param>
        /// <returns></returns>
        [HttpPost("handle/mesage")]
        [AuthAttribute]
        public ActionResult<Model.Result<string>> AddToFriendsHandle(string messageId, Model.Enum.MessageEnum.MessageHandleResult messageHandleResult, string message)
        {
            return Json(Utils.SecurityCall.SafeCall(() =>
            {
                return new BLL.Manage.FriendsManage().HanldeMessager(messageId, messageHandleResult, message);
            }));
        }


        /// <summary>
        /// 获取好友列表
        /// </summary>
        /// <returns></returns>
        [HttpGet("list")]
        [AuthAttribute]
        public ActionResult<Model.Result<List<Model.ApiResult.FriendResult.FriendsList>>> GetFriendList()
        {
            return Json(Utils.SecurityCall.SafeCall(() =>
           {
               return RestfulAPIModel.SuccessReult(new BLL.Manage.FriendsManage().GetFriendList());
           }));
        }

        /// <summary>
        /// 通过昵称或者ID查询用户
        /// </summary>
        /// <param name="nickNameOrId">昵称或者ID</param>
        /// <returns></returns>
        [HttpGet("search/list")]
        [AuthAttribute]
        public ActionResult<Model.Result<List<Model.ApiResult.FriendResult.SearchFriendListResult>>> SearchFriendListResult(string nickNameOrId)
        {
            return Json(Utils.SecurityCall.SafeCall(() =>
            {
                return RestfulAPIModel.SuccessReult(new BLL.Manage.FriendsManage().SearchFriendListResult(nickNameOrId));
            }));
        }
    }
}
